class Solution1 {
    public int search(int[] nums, int target) {
        int n=nums.length,left=0,right=nums.length-1,
                mid=0,a=0;
        while(n!=0){
            mid=(left+right)/2;
            if(nums[mid]>target){
                right=mid-1;

            }else if(nums[mid]==target){
                a=mid;
                break;
            }else if(nums[mid]<target){
                left=mid+1;

            }
            n=n/2;
        }
        if(a!=0){
            return a;
        }
        return -1;
    }
}
public class demo4 {
    public static void main(String[] args) {
        int[] nums={9,2};
        int target=9;
        Solution1 solution1=new Solution1();
        System.out.println(solution1.search(nums,target));
    }

}
